#! /bin/bash

TOMCAT_MAJOR_VERSION='8'
if [ ${#1} -gt 0 ]; then
    TOMCAT_MAJOR_VERSION=$1
fi

TOMCAT_MIRROR='https://mirrors.tuna.tsinghua.edu.cn'

TOMCAT_VERSION=`curl -s ${TOMCAT_MIRROR}/apache/tomcat/tomcat-${TOMCAT_MAJOR_VERSION}/ | grep "<a href=\"v"| sed -e "s/<[^>]*>//g" | awk 'END{print $1}' | sed 's:^.\(.*\).$:\1:'`

wget "${TOMCAT_MIRROR}/apache/tomcat/tomcat-${TOMCAT_MAJOR_VERSION}/v${TOMCAT_VERSION}/bin/apache-tomcat-${TOMCAT_VERSION}.tar.gz"
